<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>自定义事件</title> 
    </head>
    <body>
    <!-- 注意：该示例需使用Vue.js 1.x的版本 -->
        <div id = "app">
            {{message}}
            <my-component></my-component>
        </div>
        <script src = "../../vue.min.js"></script>
        <script>
            Vue.component('my-component',{
                template:'<button @click="handleDispatch">派发事件</button>',
                methods:{
                    handleDispatch() {
                        this.counter++;
                        this.$dispatch('on-message', '来自组件内部的数据');
                    }
                }
            });
            var app = new Vue({
                el: '#app',
                data:{
                    message:''
                },
                events: {
                    'on-message':function (msg) {
                        this.message=msg;
                    }
                }
            })
        </script>
    </body>
</html>